﻿Imports System.Web.Helpers
Imports SistemaINCA.Models.ViewModels

Namespace Utilitys
    Public NotInheritable Class EmailServices
        Private Shared Sub SendEmail(correo As String, Asunto As String, contenido As String, IsHTML As Boolean)
            Try
                WebMail.SmtpServer = "smtp.gmail.com"
                WebMail.SmtpPort = 587
                WebMail.EnableSsl = True
                WebMail.UserName = ConfigurationManager.AppSettings("CorreoE")
                WebMail.From = ConfigurationManager.AppSettings("CorreoE")
                WebMail.Password = EncryptationSchoolClick.ToStringInseguro(EncryptationSchoolClick.DesencriptarData(ConfigurationManager.AppSettings("CorreoEPassword")))

                'Enviar el correo a la direccion especificado
                WebMail.Send(correo, Asunto, contenido, isBodyHtml:=IsHTML)
            Catch ex As Exception
                Throw ex
            End Try
        End Sub

        Public Shared Sub Send_RecoveryMatricula(modelo As EmailRecoveryMatriculaModel, controlador As Controller)
            Try
                'Recuperamos la vista parcial convertida a String, que sera lo que recibira la persona
                Dim htmlBody = Utilitys.ControllerExtension.RenderPartialViewToString(controlador, "Email_Recovery_Matricula", modelo)
                EmailServices.SendEmail(modelo.Correo, "Recuperación del No. de Solicitud de Matricula", htmlBody, True)
            Catch ex As Exception
                Throw New ApplicationException(String.Format("Lo sentimos, ocurrió un error al intentar enviar el correo de recuperación del No. de Solicitud de Nuevo Ingreso. {0}", ex.Message))
            End Try
        End Sub
    End Class
End Namespace
